<?php

/**
 * ECSHOP 
 * ============================================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liuhui $
 * $Id: index.php 15013 2010-03-25 09:31:42Z liuhui $
*/

define('IN_ECS', true);
define('ECS_ADMIN', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'myplug/includes/lib_order.php');



$act=$_REQUEST['act'] ? $_REQUEST['act']:'default';


if ($act == 'yhprice') {
	
	
	
	
	$cartgoods = get_cart_goods();	
		
	$sql = "select goods_number from " .$ecs ->table('cart')." where user_id=".$_SESSION['user_id'];
	$gnum = $db->getOne($sql);
	
	$result['gid'] = $_POST['gid'];
	
	if($gnum>1){
		
		$result['gnum'] = $gnum;
	}

	
	
	$smarty->assign('cartgoods',              $cartgoods['goods_list']);
	
	$smarty->assign('zongji',              $cartgoods['total']);
	
	
	$sql = "select count(*) from " .$ecs ->table('cart')." where user_id=".$_SESSION['user_id']."";
	$cnum = $db->getOne($sql);
	
	
	$result['cnum'] = $cnum;
	$result['zongji'] = $cartgoods['total']['goods_amount'];

	
		
	$result['zongji']= floatval($result['zongji']);	
	$_POST['yhprice']= floatval($_POST['yhprice']);	
			
		
	if($_POST['yhclass'] == "btn btn1" ){
		
		
		$result['youhui'] = $_POST['yhprice'];
	
		$result['zongji']= $result['zongji'] - $_POST['yhprice'];
		
		
		
	}else{
		
	
	
		$result['youhui'] = $result['zongji']*$_POST['yhprice']/100;
		
		$result['zongji']= $result['zongji'] - $result['zongji']*$_POST['yhprice']/100;
		
		
		
	}
		
	if($_POST['yhhao']){
		
		//查询优惠券价格，是否使用，是否过期
		
		$sql = "select bonus_type_id from " .$ecs ->table('user_bonus')." where bonus_sn=".$_POST['yhhao']." and used_time = 0";
		$tid = $db->getOne($sql);
		
		if($tid > 0 ){
			$time=time();
			
			$sql = "select type_money from " .$ecs ->table('bonus_type')." where type_id=".$tid." and use_end_date >".$time;
			
			$result['youhui'] = $db->getOne($sql);
			$result['zongji']= $result['zongji'] - $result['youhui'];
			
		}
	}	
		

		
	$smarty->assign('sptotal',              $cartgoods['total']['goods_amount']);	
		
	$smarty->assign('result',              $result);
		
	$result['content'] = $smarty->fetch('library/total-right.lbi');
	
			
	
	
	echo json_encode($result);

	
}




?>
